//
//  MTDiscoverTableViewCell.swift
//  MT
//
//  Created by ooops on 2020/5/14.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTDiscoverTableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    class func reuseIdentity() -> String {
        return "MTDiscoverTableViewCellID"
    }
    
    lazy var discoverIconView: UIImageView = {
        let imageV = UIImageView()
        return imageV
    }()
    
    lazy var discoverTitleLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(14)
        l.textColor = UIColor.text.x1d1a1a
        return l
    }()
    
    lazy var rightAccessoryView: UIImageView = {
        let imageV = UIImageView()
        imageV.layer.borderColor = UIColor.text.x1d1a1a.cgColor
        imageV.layer.borderWidth = 1
        imageV.layer.masksToBounds = true
        imageV.isHidden = true
        imageV.image = UIImage(named: "icon_arrow_right_gary")
        return imageV
    }()
    
    lazy var rightArrowView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "icon_arrow_right_gary"))
        
        return imageV
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0xE1E1E1)
        return v
    }()
    
    var data: DiscoverItemStruct? {
        didSet {
            if let d = data {
                discoverIconView.image = UIImage(named: d.itemIcon)
                discoverTitleLabel.text = d.itemName
            }
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        makeConstraint()
        selectionStyle = .none
        if let d = data, d.type == .taskCenter {
            rightAccessoryView.isHidden = false
        } else {
            rightAccessoryView.isHidden = true
        }
    }
    
    private func setupUI() {
        contentView.addSubview(discoverIconView)
        contentView.addSubview(discoverTitleLabel)
        contentView.addSubview(rightArrowView)
        contentView.addSubview(lineView)
        contentView.addSubview(rightAccessoryView)
    }
    
    private func makeConstraint() {
        discoverIconView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(18)
            make.width.height.equalTo(30)
        }
        
        discoverTitleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(discoverIconView.snp.right).offset(9).priority(.high)
            make.right.equalTo(rightAccessoryView.snp.left).offset(-9)
        }
        
        rightAccessoryView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(rightArrowView.snp.left).offset(-14)
            make.size.equalTo(CGSize(width: 36, height: 36))
        }
        
        rightArrowView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
            make.width.height.equalTo(15)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
